using System.Collections.Generic;
using UnityEngine;

public class MultiplayerRoomsCreate : MonoBehaviour
{
	public GameObject MultiplayerRoomButonPrefab;

	public UITable table;

	public UIScrollView view;

	public GameObject swipeLeftToTrain;

	private int tableRepositionCount;

	protected bool isAligned;

	private GameObject maxRoom;

	private int maxRoomFee;

	private void Awake()
	{
		TableTennisMainNavigation instance = TableTennisMainNavigation.instance;
		if (instance.winningsCaller != null)
		{
			UITools.SetActive(instance.winningsCaller, true);
		}
	}

	private void Start()
	{
		MultiplayerRooms instance = MultiplayerRooms.instance;
		int num = 0;
		GGPlayerSettings instance2 = GGPlayerSettings.instance;
		List<GameObject> list = new List<GameObject>();
		foreach (MultiplayerRooms.RoomInfo room in instance.rooms)
		{
			GameObject gameObject = NGUITools.AddChild(table.gameObject, MultiplayerRoomButonPrefab);
			gameObject.SetActive(true);
			gameObject.name = ((char)(97 + (num + 1))).ToString();
			RoomSelectButton component = gameObject.GetComponent<RoomSelectButton>();
			component.Init(room);
			list.Add(gameObject);
			if ((maxRoom == null || (instance2.walletManager.CurrencyCount(MultiplayerRooms.instance.multiplayerCurrencyType) > 2 * room.fee && maxRoomFee < room.fee)) && (num <= 1 || GGPlayerSettings.instance.MultiplayerGamesPlayed() > 2))
			{
				maxRoom = gameObject;
				maxRoomFee = room.fee;
			}
			num++;
		}
		int num2 = instance2.Model.multiplayerWins + instance2.Model.multiplayerLoses;
		if (instance2.Level() <= 3)
		{
			maxRoom = list[1];
		}
		table.Reposition();
	}

	private void OnEnable()
	{
		GGPlayerSettings player = GGPlayerSettings.instance;
		if (!player.Model.multiplayerTutorialShown)
		{
			int firstCurrencyGift = 150;
			TrainerDialogLayer.instance.ShowOk("Welcome to Multiplayer", "Compeate in online ranked matches for great weekly prizes! Here is a " + firstCurrencyGift + " tokens to get you started!", "Ok", delegate
			{
				player.walletManager.AddCurrency(MultiplayerRooms.instance.multiplayerCurrencyType, firstCurrencyGift);
				NavigationManager.instance.Pop();
			});
			player.Model.multiplayerTutorialShown = true;
			player.Save();
		}
	}

	private void Update()
	{
		if (!isAligned)
		{
			if (maxRoom != null)
			{
				UITools.AlignToLeftOnScroll(maxRoom.GetComponent<UIWidget>(), view, 50f);
			}
			isAligned = true;
		}
	}
}
